package com.suray.wcs.service.system.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.suray.commin.core.utils.StringUtils;
import com.suray.wcs.service.system.entity.PortDB;
import com.suray.wcs.service.system.entity.WmsUrlDB;
import com.suray.wcs.service.system.mapper.WmsUrlMapper;
import com.suray.wcs.service.system.service.WmsUrlDBService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class WmsUrlDBServiceImpl extends ServiceImpl<WmsUrlMapper, WmsUrlDB> implements WmsUrlDBService {
    @Autowired
    private WmsUrlMapper wmsUrlMapper;

    //分页查询
    @Override
    public List<WmsUrlDB> selectList(WmsUrlDB wmsUrlDB) {
        QueryWrapper<WmsUrlDB> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotEmpty(wmsUrlDB.getInterfaceName())) {
            queryWrapper.lambda().like(WmsUrlDB::getInterfaceName, wmsUrlDB.getInterfaceName());
        }
        if (StringUtils.isNotEmpty(wmsUrlDB.getEffect())) {
            queryWrapper.lambda().like(WmsUrlDB::getEffect, wmsUrlDB.getEffect());
        }
        return wmsUrlMapper.selectList(queryWrapper);
    }

    @Override
    public boolean checkInterfaceNameUnique(WmsUrlDB wmsUrlDB) {
        Long urlId = StringUtils.isNull(wmsUrlDB.getUrlId()) ? -1L : wmsUrlDB.getUrlId();
        WmsUrlDB info = this.selectByInterfaceName(wmsUrlDB.getInterfaceName());
        if (StringUtils.isNotNull(info) && info.getUrlId().longValue() != urlId.longValue()) {
            return true;
        }
        return false;
    }

    /**
     * 通过接口方法名查询
     *
     * @param interfaceName 和WMS保持一致
     * @return
     */
    public WmsUrlDB selectByInterfaceName(String interfaceName) {
        LambdaQueryWrapper<WmsUrlDB> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(WmsUrlDB::getInterfaceName, interfaceName);
        return wmsUrlMapper.selectOne(queryWrapper);
    }
}
